package com.ordering.interceptor;

import java.util.Map;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
import com.ordering.entity.UserInfo;

public class UserLoginInterceptor implements Interceptor {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @Override
    public void destroy() {
    }

    @Override
    public void init() {
    }

    @Override
    public String intercept(ActionInvocation ai) throws Exception {
        Map<String,Object> session = ai.getInvocationContext().getSession();
        //Object o = session.get("user");
        
        UserInfo user =  (UserInfo) session.get("user");
        if(user == null) {
        	
            return "login";
        } else {
            //调用Action
            return ai.invoke();
        }
    }

}
